package main

import (
	"errors"
	"fmt"
)

type user struct {
	name     string
	password string
}

type student struct {
	name, nickName string
}

func findStudent(students []student, name string) (v *student, err error) {
	for _, s := range students {
		if s.name == name {
			return &s, nil
		}
	}
	return nil, errors.New("not found")
}
func findStudent2(students []student, name string) (v student, err error) {
	for _, s := range students {
		if s.name == name {
			return s, nil
		}
	}
	err = errors.New("dddd")
	v = student{"nameddd", "ddd"}
	return

}

func findUser(users []user, name string) (v *user, err error) {
	for _, u := range users {
		if u.name == name {
			return &u, nil
		}
	}
	return nil, errors.New("not found")
}
func findUser2(users []user, name string) (v user, err error) {
	for _, u := range users {
		if u.name == name {
			return u, nil
		}
	}
	return
	//return nil, errors.New("not found")
}

func main() {
	//a := []student{{"name", "cj"}}
	//
	//v, err := findStudent(a, "name")
	////fmt.Println(v, err)
	//if err != nil {
	//	fmt.Println(err)
	//	return
	//}
	//fmt.Println(v)

	if user, error := findStudent([]student{{"cc", "cj"}}, "cj"); error != nil {
		fmt.Println(error)
		return
	} else {
		fmt.Println(user.name)
	}
	/*u, err := findUser([]user{{"wang", "1024"}}, "wang")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(u.name) // wang

	if u, err := findUser([]user{{"wang", "1024"}}, "li"); err != nil {
		fmt.Println(err) // not found
		return
	} else {
		fmt.Println(u.name)
	}*/
	if u, err := findUser([]user{{"wang", "1024"}}, "wang"); err != nil {
		fmt.Println(err) // not found
		return
	} else {
		fmt.Println(u.name)
	}

}
